package testsJUnit;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestBase;

public class TestVisitorActions extends SeleneseTestBase {
	
	@Before
	public void setUp() throws Exception {
		selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://localhost:8080/");
		selenium.start();
	}

	@Test
	public void testTestRegistreren() throws Exception {
		selenium.open("/to5-veilingsite/Menu.action");
		selenium.click("link=Registreren");
		selenium.waitForPageToLoad("30000");
		selenium.type("id=CreateAccount_naam", "Pieter");
		selenium.type("id=CreateAccount_username", "Pieter");
		selenium.type("id=CreateAccount_password", "Pieter123");
		selenium.type("id=CreateAccount_passwordRepeat", "Pieter123");
		selenium.type("id=CreateAccount_woonplaats", "Oss");
		selenium.type("id=CreateAccount_adres", "Oesterstraat 44");
		selenium.type("id=CreateAccount_email", "P@live.nl");
		selenium.type("id=CreateAccount_emailRepeat", "P@live.nl");
		selenium.click("id=CreateAccount_0");
		selenium.waitForPageToLoad("30000");
		assertTrue(selenium.isTextPresent("Account aangemaakt"));
	}
	
	@Test
	public void testTestGebruikersnaamBestaatAl() throws Exception {
		selenium.open("/to5-veilingsite/Menu.action");
		selenium.click("link=Registreren");
		selenium.waitForPageToLoad("30000");
		selenium.type("id=CreateAccount_naam", "Karim");
		selenium.type("id=CreateAccount_username", "Karim");
		selenium.type("id=CreateAccount_password", "Karim123");
		selenium.type("id=CreateAccount_passwordRepeat", "Karim123");
		selenium.type("id=CreateAccount_woonplaats", "k");
		selenium.type("id=CreateAccount_adres", "k");
		selenium.type("id=CreateAccount_email", "k");
		selenium.type("id=CreateAccount_emailRepeat", "k");
		selenium.click("id=CreateAccount_0");
		selenium.waitForPageToLoad("30000");
		assertTrue(selenium.isTextPresent("Gebuikers naam bestaat al"));
	}
	
	@Test
	public void testTestLogin() throws Exception {
		selenium.open("/to5-veilingsite/Menu.action");
		selenium.click("link=Inloggen");
		selenium.waitForPageToLoad("30000");
		selenium.type("id=Login_username", "frits");
		selenium.type("id=Login_password", "Frits123");
		selenium.click("id=Login_0");
		selenium.waitForPageToLoad("30000");
		assertTrue(selenium.isTextPresent("Uitloggen"));
	}
	
	@Test
	public void testTestFoutelogin() throws Exception {
		selenium.open("/to5-veilingsite/Menu.action");
		selenium.click("link=Inloggen");
		selenium.waitForPageToLoad("30000");
		selenium.type("id=Login_username", "frits");
		selenium.type("id=Login_password", "frits");
		selenium.click("id=Login_0");
		selenium.waitForPageToLoad("30000");
		assertTrue(selenium.isTextPresent("naam of wachtwoord is niet juist"));
	}
	@After
	public void tearDown() throws Exception {
		selenium.stop();
	}

}
